home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / graphicgems4.lha / GemsIV / nurb_polyg / nurbs.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-06  |  2.5 KB  |  76 lines

  1. /*
  2.  * Nurbs.h Nurb surface processing code.
  3.  *
  4.  * John Peterson
  5.  */
  6.  
  7. #include "GraphicsGems.h"
  8.  
  9. #ifndef THINK_C
  10. typedef unsigned char Boolean;
  11. #endif
  12.  
  13. /* Rational (homogeneous) point */
  14.  
  15. typedef struct Point4Struct {
  16.     double x, y, z, w;
  17.     } Point4;
  18. typedef Point4 Vector4;
  19.  
  20. /*
  21.  * Sampled point on a surface.    This contains the point, normal and
  22.  * surface coordinates (u,v).  This structure is passed to the rendering
  23.  * code for shading, etc.
  24.  */
  25. typedef struct SurfSample {
  26.     Point3 point, normal;   /* Point on surface, normal at that point */
  27.     double normLen;        /* Used for normalizing normals */
  28.     double u, v;        /* Parameters, e.g., used for texture mapping. */
  29.     /* Note the parameter's range is determined by the surface's knot vector,
  30.      * i.e., u goes from kvU[orderU-1] to kvU[numU], and likewise for v */
  31. } SurfSample;
  32.  
  33. #define MAXORDER 20        /* Maximum order allowed (for local array sizes) */
  34.  
  35. typedef struct NurbSurface {
  36.     /* Number of Points in the U and V directions, respectivly */
  37.     long numU, numV;
  38.     /* Order of the surface in U and V (must be >= 2, < MAXORDER) */
  39.     long orderU, orderV;
  40.     /* Knot vectors, indexed as [0..numU+orderU-1] and [0..numV+orderV-1] */
  41.     double * kvU, * kvV;
  42.     /* Control points, indexed as points[0..numV-1][0..numU-1] */
  43.     /* Note the w values are *premultiplied* with the x, y and z values */
  44.     Point4 ** points;
  45.  
  46.     /* These fields are added to support subdivision */
  47.     Boolean strV0, strVn,   /* Edge straightness flags for subdivision */
  48.         strU0, strUn;
  49.     Boolean flatV, flatU;   /* Surface flatness flags for subdivision */
  50.     SurfSample c00, c0n,
  51.            cn0, cnn;    /* Corner data structures for subdivision */
  52. } NurbSurface;
  53.  
  54. extern double SubdivTolerance;    /* Screen space tolerance for subdivision */
  55.  
  56. #define CHECK( n ) \
  57.     { if (!(n)) { fprintf( stderr, "Ran out of memory\n" ); exit(-1); } }
  58.  
  59. #define DIVW( rpt, pt ) \
  60.     { (pt)->x = (rpt)->x / (rpt)->w; \
  61.       (pt)->y = (rpt)->y / (rpt)->w; \
  62.       (pt)->z = (rpt)->z / (rpt)->w; }
  63.  
  64. /* Function prototypes */
  65.  
  66. extern void DrawSubdivision( NurbSurface * );
  67. extern void DrawEvaluation( NurbSurface * );
  68.  
  69. extern long FindBreakPoint( double u, double * kv, long m, long k );
  70. extern void AllocNurb( NurbSurface *, double *, double * );
  71. extern void CloneNurb( NurbSurface *, NurbSurface * );
  72. extern void FreeNurb( NurbSurface * );
  73. extern void RefineSurface( NurbSurface *, NurbSurface *, Boolean );
  74.  
  75. extern void CalcPoint( double, double, NurbSurface *, Point3 *, Point3 *, Point3 * );
  76.